package emulator.shell.GUI.windows;

import java.util.HashMap;
import java.util.Observable;

public class WindowManager extends Observable {
	
	private HashMap<Integer, ManagedWindow> window_map = new HashMap<Integer, ManagedWindow>();

	public ManagedWindow createWindow(int id, String name)
	{
		ManagedWindow window = new ManagedWindow(this, name);
		window.setID(id);
		window_map.put(id, window);
		setChanged();
		notifyObservers();
		return window;
	}

	public void unregisterWindow(ManagedWindow managedWindow)
	{
		if (window_map.remove(managedWindow.getID()) != null)
		{
			setChanged();
			notifyObservers();
		}
	}
	
	public boolean isWindowActive(int id)
	{
		return window_map.containsKey(id);
	}

	public void closeWindow(int id)
	{
		ManagedWindow window = window_map.get(id);
		if (window != null)
		{
			unregisterWindow(window);
			window.setVisible(false);
		}
	}
}
